package com.yige.service.mongoService

import com.mongodb.DBCollection
import com.mongodb.DBObject
import com.yige.common.SystemConstant
import com.yige.service.LessonStuService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

/**
 * Created by sunhao on 2015/11/12 0012.
 */

@Service
class MongoLessonStuService extends BasicMongoServiceImp implements LessonStuService {

    @Autowired
    MongoTeacherService teacherService

    @Autowired
    MongoStudentService studentService

    @Override
    DBCollection getCollection() {
        return mongoTemplate.getCollection(SystemConstant.MONGODB_COL_LESSON_STU)
    }

    @Override
    List<DBObject> findStuForLesson(Object lessonId, Object teacherId) {
        def list = new ArrayList(),studentList = teacherService.findAllStudentForTeacher(teacherId)
        def student_db
        studentList.each {studentId->
            student_db = studentService.findOneById(studentId)
            student_db.lessons.each{
                if(lessonId.equals(it.id)){
                    list.add(student_db)
                }
            }
        }
        return list
    }
}
